﻿var cssChangeArr = ["card0","card1","card2","card3","card4","card5"]
var leftNumArr = [30, 40,90, 120,140, 160]

$(document).ready(function(){
	
	
	$("div[url]").hover(cardMouseOverHandle,cardMouseOutHandle);
	
	$("div[url]").click(cardClickHandle);
	
	$("div[url]").attr("currentCard","false");
	$("div[url]").attr("classIndex",0);
	$("div[url]").attr("mouseoverCard","false");
	$("div[url]").eq(0).attr("currentCard","true");
	setInterval(generalInterval,80)
	//generalInterval();
}); 
function cardClickHandle(){
	parent.gotoPage(Number($(this).attr("url")));
}

function cardMouseOverHandle(){
	
	if($(this).attr("currentCard") == "false"){
		//alert("over")
		$(this).attr("mouseoverCard","true");
	}
	
}
function cardMouseOutHandle(){
	//alert("out")
	$(this).attr("mouseoverCard","false");
}




function generalInterval(){
	
	if(parent.currentPage != $("div[url][currentCard='true']").attr("url")){
		$("div[url]").attr("currentCard","false");
		$("#page" + parent.currentPage).attr("currentCard","true");
		
	}
	
	var leftNum = 0;
	var divArr = $("div[url]");
	for(var i=0,il=divArr.length;i<il;i++){
		var divObj = divArr.eq(i);
		var classIndex = divObj.attr("classIndex");

		if(divObj.attr("currentCard")  == "true"){
			if(!divObj.hasClass(cssChangeArr[cssChangeArr.length - 1]) ){
				divObj.removeClass(cssChangeArr[classIndex])
				divObj.addClass(cssChangeArr[++classIndex])
				divObj.attr("classIndex",classIndex);
			}
		}else{
			if(!divObj.hasClass(cssChangeArr[0]) ){
				divObj.removeClass(cssChangeArr[classIndex])
				divObj.addClass(cssChangeArr[--classIndex])
				divObj.attr("classIndex",classIndex);
			}
		}
		
		var marginTopNum = divObj.css("top");
		marginTopNum = parseInt( marginTopNum.substr(0,marginTopNum.length - 2))
		//alert(marginTopNum > -20)
		
		if(divObj.attr("mouseoverCard")  == "true"){
			
			if( marginTopNum > -20 ){
				
				divObj.css( "top" , ( (marginTopNum-5)<-20)?-20:(marginTopNum-5) + "px"  )
			}
		}else{
			//alert(2)
			if(marginTopNum < 0 ){
				
				divObj.css( "top" , ( (marginTopNum+5)>0)?0:(marginTopNum+5) + "px"  )
			}
		}
		
		
		divObj.css("left",leftNum + "px")
		leftNum += leftNumArr[classIndex];
		
		
		//alert(divArr.eq(i).attr("id"))
	}

	
}

